package gui;

import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
 * A button that holds the image of a sprite. Used in the sprite palette.
 */
public class SpriteButton extends JButton
{

    public static final Dimension DEFAULT_SIZE = new Dimension(100, 100);

    private ImageIcon icon;

    private DrawingBoard owner;

    public SpriteButton(DrawingBoard owner, ImageIcon icon)
    {
        super(icon);
        this.owner = owner;
        this.icon = icon;
        this.setPreferredSize(DEFAULT_SIZE);
        this.addActionListener(new ClickAction());
    }

    private class ClickAction implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            DraggableImage img = new DraggableImage(icon);
            owner.newSprite(img);
        }
    }

}
